package com.lebang.controller.api.bus;

import com.alibaba.fastjson.JSONObject;
import com.lebang.common.Login;
import com.lebang.feign.bus.MemberWithdrawalRecordFeign;
import com.lebang.service.buss.MemberService;
import com.lebangweb.common.TextUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 *
 * @author ljx
 * @date 2020-12-27
 */
@Controller
@RequestMapping("/sys/memberwithdrawalrecord")
public class MemberWithdrawalRecordApi {
    @Autowired
    private MemberWithdrawalRecordFeign feign;
    @Autowired
    private MemberService memberService;

    @GetMapping("/list")
    public String list() {
        return "/memberwithdrawalrecord/list";
    }

    @Login
    @ApiOperation(value = "分页")
    @PostMapping("/list")
    @ResponseBody
    public JSONObject list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit,String status,
                           @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime star,
                           @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        return JSONObject.parseObject(JSONObject.toJSONString(feign.list(page, limit,status,star,end).getData()));
    }

    @Login
    @ApiOperation(value = "修改状态")
    @PostMapping("/updatestatus")
    @ResponseBody
    public JsonData updateStatus(HttpServletRequest request, String memberId, String imei,String phone, String wxOpenid, Integer configId) {
        if (TextUtil.isEmpty(phone)){
            return Callback.fail("201","手机号不能为空");
        }
        return feign.updateStatus(memberId,imei,phone,wxOpenid,configId);
    }

}
